<template>
    <div class="swiper-container banner-content">
        <div class="swiper-wrapper">
            <div class="swiper-slide" v-for="item in bannerList" :key="item.id"><img :src="item.img" :alt="item.title"></div>
        </div>
        <!-- Add Pagination -->
        <div class="swiper-pagination"></div>
    </div>
</template>

<script>

//引入axios封装的接口
import {getBanner} from '../utils/api'
//引入swiper
import Swiper from "swiper"
export default {
    data(){
        return{
            bannerList:[]
        }
    },
    mounted() {
        getBanner().then(res=>{
            this.bannerList = res.list
        }).catch(err=>{
            console.log(err);
        })

    },    
    updated() {
        new Swiper(".banner-content", {
            slidesPerView: 1.3,//设置视图窗口可以放几个li，来设置每个li的宽度
            spaceBetween: 30,
            centeredSlides: true,
            loop: true,
            pagination: {
                el: '.swiper-pagination',
                clickable: true,
            },
            autoplay:true
            /*autoplay: {
                delay: 3000,//延时
                stopOnLastSlide: false,//切换到最后一个是否停顿
                disableOnInteraction: true,//鼠标滑入是否停顿
            },*/
        });
    },
};
</script>

<style  scoped>
/* 引入swiper的css */
@import '../../node_modules/swiper/css/swiper.min.css';

.swiper-slide {
    text-align: center;
    font-size: 18px;
    /* background: #fff; */
    /* margin: ; */
    /* Center slide text vertically */
    display: -webkit-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
    align-items: center;
    transition: 300ms;
    transform: scale(0.8);
}

.swiper-slide-active,.swiper-slide-duplicate-active{
    transform: scale(1);
}
.swiper-slide img{
    width: 6.7rem;
    height: 3.9rem;
    border-radius: 0.05rem;
}
</style>